/******************************************************************************
 * Copyright 2024 zhangcong. All Rights Reserved.
 *****************************************************************************/

#pragma once
#include <stdint.h>
#include <thread>
#include <map>
#include <string>
#include <memory>
#include "business/recordbusiness/proto/sensor_proto.h"
#include "business/recordbusiness/proto/store_task_proto.h"
#include "common/sensordata.h"
#include "business/recordbusiness/storetask.h"

class StoreTaskManager
{
private:
    StoreTaskManager() {
        m_storeTaskRunFlag = false;
    }

    ~StoreTaskManager() {
        m_storeTaskRunFlag = false;
        m_storeTaskThread->detach();
    }

public:
    static StoreTaskManager* GetInstance();
    int32_t init();
    int32_t proc();
    void StoreTaskFunc();
    void PubUploadFileEndInfo(json &fileEndInfo);
    void ReqCurStoreTask();
    void AddStoreTask(const std::string &taskID, const StoreTaskInfo &taskInfo);
    void StartStoreTask(const std::string &taskID);
    void PauseStoreTask(const std::string &taskID);
    void DeleteStoreTask(const std::string &taskID);
    void DeleteStoreFile(const std::string &filedir);

private:
    static StoreTaskManager* m_Instance;
    std::map<std::string, std::shared_ptr<StoreTask>> m_StoreTaskArray;
    std::unique_ptr<std::thread> m_storeTaskThread;
    bool   m_storeTaskRunFlag;
    void *m_context = nullptr;
    void *m_sub = nullptr;
    void *m_pub = nullptr;
    std::string m_pubtopic;
    std::string m_subtopic;
    std::string m_dataUuid;
    std::string m_coreUuid;
};
